﻿using System;
using System.Data;
using System.IO;
using System.Data.OleDb;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using BLL;
using Model;
using Ysb.Components;

using DAL;
using Aspose.Cells;
public partial class Admin_UserBillManage : System.Web.UI.Page
{

    WayBill mbill = new WayBill();
    WayBillService mbills = new WayBillService();
    string gvUniqueID = String.Empty;
    const string vsKey = "searchCritriam";
    Tools newtools = new Tools();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (AdminCheck.Check(this, 18))
        {
            if (!Page.IsPostBack)
            {
                StateLoad();
                anolb.Text = Request.QueryString["ano"].ToString();
                namelb.Text = Request.QueryString["name"].ToString();
                DataLoad("CreateUserID=" + Request.QueryString["ID"].ToString());

            }
        }
        else
        {
            Response.Redirect(AdminCheck.RedirectPage);
        }



    }
    private void DataLoad(string sql)
    {
        ViewState["sql"] = sql;
        NewsPage.RecordCount = new PublicSqlService().GetCoun("BID", "Tbl_WayBill", sql);

        BindData(sql);
    }
    private void BindData(string sql)
    {

        string getword = "sep,TrackingNo,NoOfPiece,UPEXState,Sender,Receiver,ChargedWt,FlightNo,BillState,Total,CreateDate,Memo1,StateID,SepTotal,SepChargedWt";
        billlist.DataSource = new PublicSqlService().GetDataPage("Tbl_WayBill", NewsPage.RecordCount, NewsPage.PageSize, NewsPage.CurrentPageIndex, "BID", 1, true, getword, sql);
        billlist.DataBind();



    }
    protected void NewsPage_PageChanged(object sender, EventArgs e)
    {

        BindData((string)ViewState["sql"]);

    }

    public DataTable getrpro(string tn)
    {
        string getword = "SepNo,TrackingNo,SBState,SendBy,CHNReceiver,Pieces,ChargedWt,FlightNo,CreateDate,Logo,Memo1,Total,State";
        return new PublicSqlService().GetData(getword, "Tbl_SepBill", "TrackingNo='" + tn.Trim() + "'");
    }

    private void StateLoad()
    {
        statetxt.DataSource = new BillStateService().GetAllList();
        statetxt.DataTextField = "Description";
        statetxt.DataValueField = "BSID";
        statetxt.DataBind();
        statetxt.Items.Insert(0, "");

    }


    protected void searchbtn_Click(object sender, ImageClickEventArgs e)
    {
        string sql = "CreateUserID=" + Request.QueryString["ID"].ToString();


        if (stno.Value.Trim() != "")
        {
            sql += " and TrackingNo like'%" + stno.Value.Trim() + "%'";
        }
         if (sepno.Value.Trim() != "")
        {
            sql += " and sepdetail like'%" + sepno.Value.Trim() + "%'";
        }
        if (recervertxt.Value.Trim() != "")
        {
            sql += " and Receiver like'%" + recervertxt.Value.Trim() + "%'";
        }

        if (statetxt.SelectedItem.Value.Trim() != "")
        {
            sql += " and StateId= " + statetxt.SelectedItem.Value.Trim();
        }
        if (accnotxt.Value.Trim() != "")
        {
            sql += " and Sender like'%" + accnotxt.Value.Trim() + "%'";
        }

        if (startime.Value.Trim() != "")
        {

            sql += " and CreateDate  >= cast('" + startime.Value.Trim() + "  00:00:00 " + "' as datetime)  ";
        }

        if (endtime.Value.Trim() != "")
        {

            sql += " and CreateDate  <= cast('" + endtime.Value.Trim() + " 23:59:59' as datetime)  ";
        }





        if (zzhtxt.Value.Trim() != "")
        {
            sql += " and FlightNo   like'%" + zzhtxt.Value.Trim() + "%'";

        }

        DataLoad(sql);


    }

}

